package Jdbc;
import java.sql.*;
public class work0 {
    public static void main(String[] args) {
        Connection conn = DBUtil.getConnection();
        String sql = "INSERT INTO s_student(sname,gradeid) VALUES (?,?)";
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            ps.setString(1,"包租婆");
            ps.setLong(2,2);
            ps.executeUpdate();
            rs = ps.getGeneratedKeys();
            while (rs.next()) {
                System.out.println(rs.getLong(1));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            DBUtil.close(conn,ps,null);
        }
    }
}
